const service = require('../request').service;
const model = require("../../utils/modelUtil");

/**
 * 广告
 */
class Gold {
    constructor(user) {
        this.user = user;
    }

    /**
     * 获取广告数据
     * @returns {Promise<unknown>}
     */
    getAdvertisementData(type) {
        return new Promise((resolve, reject) => {
            service({
                method: 'POST',
                url: this.user.game.reqUrl + '/GetNewAdvertisementNum',
                data: model.userModel('GetNewAdvertisementNum', {typeID: type, artLevel: this.user.game.other.baseValueAy[33]}, this.user.game.isWeb, this.user.game.data),
            }).then(res => {
                const resData = res.data;
                resolve(resData.code===200?resData.MsgData:{});
            }).catch(err => {
                reject(err);
            })
        })
    }

    /**
     * 获取广告奖励
     * @returns {Promise<unknown>}
     */
    getAdvertisementReward(type) {
        return new Promise((resolve, reject) => {
            service({
                method: 'POST',
                url: this.user.game.reqUrl + '/LookNewAdvertisement',
                data: model.userModel('LookNewAdvertisement', {artLevel: this.user.game.other.baseValueAy[33], typeID: type, eventID: 0}, this.user.game.isWeb, this.user.game.data),
            }).then(res => {
                const resData = res.data;
                resolve(resData.code===200?resData.MsgData:{});
            }).catch(err => {
                reject(err);
            })
        })
    }
}

module.exports = Gold;